package com.projectzqjz.parttimework.ui.activity;

import android.view.View;
import android.widget.EditText;

import com.projectzqjz.parttimework.App;
import com.projectzqjz.parttimework.R;
import com.projectzqjz.parttimework.base.BaseActivity;
import com.projectzqjz.parttimework.entity.PartBaseEntity;
import com.projectzqjz.parttimework.net.MyCallback;
import com.projectzqjz.parttimework.net.Task;
import com.projectzqjz.parttimework.utils.NewsToastUtils;
import com.projectzqjz.parttimework.utils.SPUtils;
import com.projectzqjz.parttimework.utils.ScreenUtil;
import com.projectzqjz.parttimework.utils.TitleBuilder;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Response;

public class PartFeedBackActivity extends BaseActivity {
    @BindView(R.id.edit_content)
    EditText edit_content;//反馈内容
    @BindView(R.id.ed_qq)
    EditText ed_qq;//邮箱或qq

    @OnClick({R.id.tv_submit})
    public void onViewClicked(View view) {
        if (ScreenUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.tv_submit: //提交反馈信息
                String content = edit_content.getText().toString();
                String edQQ = ed_qq.getText().toString();
                if (content.equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "反馈内容不能为空！");
                } else if (edQQ.equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "邮箱或QQ不能为空！");
                } else {
                    subMit(content, edQQ);
                }
                break;

        }
    }

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {

    }

    @Override
    protected boolean isStatusBarBlack() {
        return true;
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_feed_back;
    }

    @Override
    public void initView() {
        new TitleBuilder(this).setTitleText("意见反馈")
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });
    }

    @Override
    public void initData() {

    }

    //上传反馈信息
    private void subMit(String content, String contact) {
        String userId= SPUtils.get(App.getContext(),"userId","")+"";
        Task.getApiService().subMitFeedBack(userId, content, contact).enqueue(new MyCallback<PartBaseEntity>(PartFeedBackActivity.this) {
            @Override
            protected void onSuccess(Response<PartBaseEntity> response) {
                assert response.body() != null;
                NewsToastUtils.showToast(App.getContext(), response.body().getMsg());
                finish();
            }

            @Override
            protected void onFailure(Throwable t) {

            }
        });
    }
}
